//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateCandidate {
        private readonly ICandidateRepository _candidateRepository;

        public CreateCandidate(ICandidateRepository candidateRepository) {
            _candidateRepository = candidateRepository;
        }

        public void Execute(Guid userId, ICreateCandidateCommand candidateForm) {
            if (candidateForm == null)
                throw new ArgumentNullException("candidateForm");

            try {
                var candidate = candidateForm.ConvertToEntity();
                _candidateRepository.Create(candidate);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
